/*----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the 
License at http://www.mozilla.org/MPL/
	
Software distributed under the License is distributed on 
an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, 
either express or implied. 
See the License for the specific language governing rights and 
limitations under the License.
	
The Original Code is Fever RS ( ActionScript 3 ) Framework code.
	
The Initial Developer of the Original Code is Romain Ecarnot.
Portions created by Initial Developer are Copyright (C) 2006
the Initial Developer. All Rights Reserved.
	
Contributor(s):
	
Unless required by applicable law or agreed to in writing, 
software distributed under the License is distributed on 
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
OF ANY KIND, either express or implied.
See the License for the specific language governing permissions 
and limitations under the License.
----------------------------------------------------------------------------*/

package fever.data.validators.strategy 
{
	import fever.data.validators.ValidatorStrategy;		

	/**
	 * The NumberValidatorStrategy class ensures that a String represents 
	 * a valid number.
	 * 
	 * @see fever.data.validators.Validator
	 * @see fever.data.validators.strategy Fever Implemented strategies
	 * 
	 * @author Romain Ecarnot
	 */
	public class NumberValidatorStrategy extends ValidatorStrategy
	{
		//--------------------------------------------------------------------
		// Private properties
		//--------------------------------------------------------------------
		
		/** @private */
		protected static var DECIMAL_CHARS : String = "0123456789";
			
		private var _allowNegative : Boolean;
		private var _decimalSeparator : String;
		private var _domain : String;
		private var _maxValue : Number;
		private var _minValue : Number;
		private var _precision : int;
		private var _thousandsSeparator : String;
		
		
		//--------------------------------------------------------------------
		// Public properties
		//--------------------------------------------------------------------	
			
		/**
		 * Specifies whether negative numbers are permitted.
		 * 
		 * @default true
		 */
		public function get allowNegative() : Boolean { return _allowNegative; }
		/** @private */
		public function set allowNegative ( o : Boolean ) : void { _allowNegative = o;	}
		
		/**
		 * The character used to separate the whole from the fractional part of the number.
		 * 
		 * @default "."
		 */
		public function get decimalSeparator() : String { return _decimalSeparator; }
		/** @private */
		public function set decimalSeparator ( o : String ) : void { _decimalSeparator = o;	}
		
		/**
		 * Type of number to be validated.
		 * 
		 *  @default "real"
		 */
		public function get domain() : String { return _domain; }
		/** @private */
		public function set domain ( o : String ) : void { _domain = o;	}
		
		/**
		 * Maximum value for a valid number.
		 * 
		 * @default NaN
		 */
		public function get maxValue() : Number { return _maxValue; }
		/** @private */
		public function set maxValue ( o : Number ) : void { _maxValue = o;	}
		
		/**
		 * Minimum value for a valid number.
		 * 
		 * @default NaN
		 */
		public function get minValue() : Number { return _minValue; }
		/** @private */
		public function set minValue ( o : Number ) : void { _minValue = o;	}
				
		/**
		 * The maximum number of digits allowed to follow the decimal point.
		 * 
		 * @default -1 ( means ignored )
		 */
		public function get precision() : int { return _precision; }
		/** @private */
		public function set precision ( o : int ) : void { _precision = o;	}
		
		/**
		 * The character used to separate thousands in the whole part of the number.
		 * 
		 * @default ","
		 */
		public function get thousandsSeparator() : String { return _thousandsSeparator; }
		/** @private */
		public function set thousandsSeparator ( o : String ) : void { _thousandsSeparator = o;	}
		
		
		//--------------------------------------------------------------------
		// Public API
		//--------------------------------------------------------------------
		
		/**
		 * Constructor.
		 */
		public function NumberValidatorStrategy()
		{
			super();
			
			_allowNegative = true;
			_decimalSeparator = ".";
			_domain = 'real';
			_maxValue = NaN;
			_minValue =NaN;
			_precision = -1;
			_thousandsSeparator = ",";
		}	
		
		/** 
		 * @inheritDoc
		 */
		override public function validate( value : Object ) : void
		{
			super.validate( value );
			
			if( !_isNullValue(value) )
			{
				//1. Test each characters using decimal suite
				//
			}
		}
	}
}
